package com.anc.platform.model.platform.biz.impl;


import api.model.UserDeleteDTO;
import com.anc.platform.model.platform.biz.ScmLogisticsCompanyBizService;
import com.anc.platform.model.platform.client.SysUserClient;
import com.anc.platform.model.platform.entity.ScmLogisticsCompany;
import com.anc.platform.model.platform.service.IScmLogisticsCompanyService;
import com.anc.platform.config.AopProxy;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
//import io.seata.spring.annotation.GlobalTransactional;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Slf4j
@Service
public class ScmLogisticsCompanyBizServiceImpl implements ScmLogisticsCompanyBizService, AopProxy<ScmLogisticsCompanyBizServiceImpl> {
    /**
     * redis缓存空间名称
     */
    private static final String CACHE_NAME = "redis:scm_logistics_company";
    @Autowired
    private IScmLogisticsCompanyService iScmLogisticsCompanyService;
    @Autowired
    private SysUserClient sysUserClient;
    @Override
    public List<ScmLogisticsCompany> findBytypeList(Integer logisticsCompanyType) throws InterruptedException {
        List<ScmLogisticsCompany> bytypeList2 = this.self().findBytypeList2(logisticsCompanyType);
        return  bytypeList2;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
//    @GlobalTransactional
    public void updateForFeign(String id) {
        ScmLogisticsCompany byId=new ScmLogisticsCompany();
        LambdaUpdateWrapper<ScmLogisticsCompany> wrapper = new LambdaUpdateWrapper<>();
        wrapper.set(ScmLogisticsCompany::getIsDelete,4);
        wrapper.eq(ScmLogisticsCompany::getId,id);
        iScmLogisticsCompanyService.update(wrapper);
        UserDeleteDTO userDeleteDTO=new UserDeleteDTO();
        userDeleteDTO.setUserId("258895339698823237");
        try {
            sysUserClient.updateUser(userDeleteDTO);
        }catch (Exception e){
//            sysUserClient.updateUser(userDeleteDTO);

        }
    }

    @Cacheable(cacheNames = {CACHE_NAME}, keyGenerator = "keyGenerator", unless = "#result == null")
    public List<ScmLogisticsCompany> findBytypeList2(Integer logisticsCompanyType) throws InterruptedException {
        return iScmLogisticsCompanyService.findBytypeList(logisticsCompanyType);
    }

}
